package edu.sctu.zhoumengxue.day201506.day20150623;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * 解析URL
 * Created by user12 on 2015/6/23.
 */
public class JsonUtil {
    public JsonAppbean getJson(String json) {

        JsonAppbean jsonAppbean = new JsonAppbean();
        JSONObject jsonObject = JSON.parseObject(json);
        jsonAppbean.error = jsonObject.getIntValue("error");
        jsonAppbean.message = jsonObject.getString("message");
        String list = jsonObject.getString("list");
        JSONArray array = JSON.parseArray(list);

        for (int i = 0; i < array.size(); i++) {

            ListAppbean listAppbean = new ListAppbean();
            listAppbean.rec_id = array.getJSONObject(i).getString("rec_id");
            listAppbean.goods_id = array.getJSONObject(i).getString("goods_id");
            listAppbean.category_id = array.getJSONObject(i).getString("category_id");
            listAppbean.brand_id = array.getJSONObject(i).getString("brand_id");
            listAppbean.goods_name = array.getJSONObject(i).getString("goods_name");
            listAppbean.goods_price = array.getJSONObject(i).getString("goods_price");
            listAppbean.goods_introduce = array.getJSONObject(i).getString("goods_introduce");

            jsonAppbean.list.add(listAppbean);
        }

        return jsonAppbean;

    }

}
